<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>质检系统</title>
    <link rel="shortcut icon" href="favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../js/element-ui-2.13.0/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../styles/common.css"/>
    <link rel="stylesheet" href="../styles/index.css"/>
    <link rel="stylesheet" href="../styles/icon/iconfont.css"/>
    <style>
        .body {
            min-width: 1366px;
        }

        .app-main {
            height: calc(100% - 64px);
        }

        .app-main .divTmp {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
<div class="app" id="app">
    <div class="app-wrapper openSidebar clearfix">
        <!-- sidebar -->
        <div class="sidebar-container">
            <div class="logo">
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <el-menu
                        :default-active="defAct"
                        :unique-opened="false"
                        :collapse-transition="false"
                        background-color="#343744"
                        text-color="#bfcbd9"
                        active-text-color="#f4f4f5"
                >
                    <div v-for="item in menuList" :key="item.id">
                        <el-submenu :index="item.id" v-if="item.children && item.children.length>0">
                            <template slot="title">
                                <i class="iconfont" :class="item.icon"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item
                                    v-for="sub in item.children"
                                    :index="sub.id"
                                    :key="sub.id"
                                    @click="menuHandle(sub,false)"
                            >
                                <i :class="iconfont" :class="sub.icon"></i>
                                <span slot="title">{{sub.name}}</span>
                            </el-menu-item
                            >
                        </el-submenu>
                        <el-menu-item v-else :index="item.id" @click="menuHandle(item,false)">
                            <i class="iconfont" :class="item.icon"></i>
                            <span slot="title">{{item.name}}</span>
                        </el-menu-item>
                    </div>
                </el-menu>
            </el-scrollbar>
        </div>
        <div class="main-container">
            <div class="navbar">
                <div class="head-lable">
              <span v-if="goBackFlag" class="goBack" @click="goBack()"
              ><img src="../img/zhongfeng.png" alt=""/> 返回</span
              >
                    <span>{{headTitle}}</span>
                </div>
                <div class="right-menu">
                    欢迎您，<el-link type="primary" @click="gotoUrl('5')" >{{realName}}</el-link>&nbsp;&nbsp;&nbsp;&nbsp;
                    <el-link class="outLogin" type="primary" @click="logout">退出</el-link>
                </div>
            </div>
            <div class="app-main" v-loading="loading">
                <div class="divTmp" v-show="loading"></div>
                <iframe
                        id="cIframe"
                        class="c_iframe"
                        name="cIframe"
                        :src="iframeUrl"
                        width="100%"
                        height="auto"
                        frameborder="0"
                        v-show="!loading"
                ></iframe>
            </div>
        </div>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../js/vue.js"></script>
<script src="../js/element-ui-2.13.0/lib/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../js/request.js"></script>
<script src="../../js/login.js"></script>
<script src="../js/query.js"></script>
<script>

    new Vue({
        el: '#app',
        data() {
            return {
                jump: '',
                defAct: '1',
                menuActived: '',
                userInfo: {},
                realName:'',
                userType:'',
                menuList: [
                    {
                        id: '1',
                        name: '质检信息',
                        url: '../page/quality/list.html'
                    },
                    {
                        id: '2',
                        name: '用户管理',
                        url: '../page/user/list.html'
                    }
                ],
                iframeUrl: '../page/quality/list.html',
                userPage: '../page/user/list.html',
                headTitle: '众峰管理系统',
                goBackFlag: false,
                loading: true,
                timer: null
            }
        },
        computed: {},
        created() {
            this.closeLoading()
            this.dealCookie()
            if(this.realName == "" | this.realName == null){
                window.location.href = '../page/login/login.html';
            }
            if (this.userType != 0){
                this.menuList.splice(4,1)
            }
            this.jump = localStorage.getItem("jump")
            if (this.jump == '1'){
                const menu = this.menuList.find(item => item.id === '1')
                window.menuHandle = this.menuHandle(menu,false)
            }
        },
        beforeDestroy() {
            this.timer = null
            clearTimeout(this.timer)
        },
        mounted() {
            window.menuHandle = this.menuHandle
        },
        methods: {

            gotoUrl(id){
                const menu = this.menuList.find(item => item.id === id)
                window.menuHandle = this.menuHandle(menu,false)
            },
            dealCookie() {
                // 对cookie操作
                var cookies = document.cookie;
                var cookie_array = cookies.split(";");
                for (var i = 0; i < cookie_array.length; i++) {
                    var cookie = cookie_array[i];
                    var array = cookie.split("=");
                    if (array[0] === "realName") {
                        this.realName = array[1];
                    }
                    if (array[0] === " userType") {
                        this.userType = array[1];
                    }
                }
            },
            logout() {
                logoutApi().then((res) => {
                    if (res.code === 200) {
                        localStorage.removeItem('realName')
                        window.location.href = '../page/login/login.html'
                    }
                })
            },
            goBack() {
                // window.location.href = 'javascript:history.go(-1)'
                const menu = this.menuList.find(item => item.id === this.menuActived)
                // this.goBackFlag = false
                // this.headTitle = menu.name
                this.menuHandle(menu, true)
            },
            menuHandle(item, goBackFlag) {
                this.loading = true
                this.menuActived = item.id
                this.defAct = item.id;
                this.iframeUrl = item.url
                this.headTitle = item.name
                this.goBackFlag = goBackFlag
                this.closeLoading()
            },
            closeLoading() {
                this.timer = null
                this.timer = setTimeout(() => {
                    this.loading = false
                }, 1000)
            }
        }
    })
</script>
</body>
</html>
